/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package taini;

/**
 *
 * @author Aini
 */

import java.io.File;

public class Delete {
    String filenama = "";


    public Delete(String namaFile)
    {

    this.filenama = namaFile;
    hapus(namaFile);
    }

    public void hapus(String filehapus)
    {
    File f = new File(filehapus);

    // Make sure the file or directory exists and isn't write protected
//    if (!f.exists())
//      throw new IllegalArgumentException(
//          "Delete: no such file or directory: " + filehapus);
//
//    if (!f.canWrite())
//      throw new IllegalArgumentException("Delete: write protected: "
//          + filehapus);

    // If it is a directory, make sure it is empty
//    if (f.isDirectory()) {
//      String[] files = f.list();
//      if (files.length > 0)
//        throw new IllegalArgumentException(
//            "Delete: directory not empty: " + filehapus);
//    }

    // Attempt to delete it
    boolean success = f.delete();

//    if (!success)
//      throw new IllegalArgumentException("Delete: deletion failed");
    }


  public static void main(String[] args) {
   Delete del = new Delete("New Text Document.txt");
   del.hapus("New Text Document.txt");
    // A File object to represent the filename
    
  }

}
